package org.nowcoder.leetcode.hashTable;

import java.util.HashMap;
import java.util.Map;

/**
 * Title  : 205. Isomorphic Strings
 * Source : https://leetcode.cn/problems/isomorphic-strings/?envType=study-plan-v2&envId=top-interview-150
 * Author : XrazYang
 * Date   : 2023-08-01
 */
public class LeetCode_205 {
    public boolean isIsomorphic(String s, String t) {
        Map<Character, Character> map = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            char sc = s.charAt(i);
            char tc = t.charAt(i);
            if (map.get(sc) != null) {
                if (map.get(sc) != tc) {
                    return false;
                }
            } else {
                //不存在的情况
                if (!map.containsValue(tc)) {
                    map.put(sc, tc);
                } else {
                    return false;
                }
            }
        }
        return true;
    }
}
